package com.limao.DBProvider;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.limao.DBDataClass.CrowdPrestigeParmDataClass;
import com.limao.DbConnection.DbConnectionManager;

public class CrowdPrestigeParmProvider {
	
	private static CrowdPrestigeParmProvider instance;

	public static CrowdPrestigeParmProvider getInstance() {
		if(instance==null) instance=new CrowdPrestigeParmProvider();
		return instance;
	}
	
  
	private CrowdPrestigeParmProvider() {

	}

	private CrowdPrestigeParmDataClass encapOrderData(ResultSet rs) throws Exception{
		
		CrowdPrestigeParmDataClass orderData = new CrowdPrestigeParmDataClass();
		
		orderData.parmid=rs.getString("parmid");
		orderData.type=rs.getString("type");
		orderData.level=rs.getString("level");
		orderData.state=rs.getString("state");
		orderData.regular_num0=rs.getString("regular_num0");
		orderData.regular_num1=rs.getString("regular_num1");
		orderData.regular_num2=rs.getString("regular_num2");
		orderData.regular_num3=rs.getString("regular_num3");
		orderData.regular_num4=rs.getString("regular_num4");
		orderData.regular_num5=rs.getString("regular_num5");
		
		orderData.ctime=rs.getString("ctime");
		orderData.utime=rs.getString("utime");
		
		return orderData;
	}
			
	public CrowdPrestigeParmDataClass Load_CrowdPrestigeParm(int type,int level)
	{
		CrowdPrestigeParmDataClass tmp=null;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
			try {
				 
				con = DbConnectionManager.getConnection();
				pstmt = con.prepareStatement("select * from cd_sys_prestigeparm where type=? and level=? and state=1 order by parmid desc limit 1");
				pstmt.setInt(1, type);
				pstmt.setInt(2, level);
				rs = pstmt.executeQuery();
				if (rs.next()) {
					tmp=encapOrderData(rs);
				}

			} catch (Exception e) {
				e.printStackTrace();
				tmp=null;
			} finally {
				DbConnectionManager.closeConnection(rs, pstmt, con);
			}
			return tmp;
	}
	
	
}
